package com.sc.web.gwt.client.presenter;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.sc.web.gwt.client.ClientFactory;
import com.sc.web.gwt.client.place.AdministratorWidgetPlace;
import com.sc.web.gwt.client.place.LoginWidgetPlace;
import com.sc.web.gwt.client.place.RegisterWidgetPlace;
import com.sc.web.gwt.client.view.LoginWidget.LoginWidgetView;

public class LoginActivity extends AbstractActivity implements LoginWidgetView.Presenter {
    // Used to obtain views, eventBus, placeController
    // Alternatively, could be injected via GIN
    private ClientFactory clientFactory;
    private LoginWidgetView loginWidgetView;

    public LoginActivity(LoginWidgetPlace place, ClientFactory clientFactory) {
        this.clientFactory = clientFactory;
    }

    public void start(AcceptsOneWidget panel, EventBus eventBus) {
        loginWidgetView = clientFactory.getLoginWidgetView();
        loginWidgetView.setPresenter(this);
        panel.setWidget(loginWidgetView.asWidget());
    }

    public void goTo(Place place) {
        clientFactory.getPlaceController().goTo(place);
    }

    public void clearFields() {
        loginWidgetView.clearFields();
    }

    public void login() {
        if (true) {
            goTo(new AdministratorWidgetPlace());
        }
    }

    public void redirectToRegisterWidget() {
        goTo(new RegisterWidgetPlace());
    }
}
